Skip to content

Drawing text: lines are measured before they're set, and can break between words to fit a width (#4890) - #12349

Merged
bherbruck merged 1 commit into
tangency-labs:drawingsfrom
CamWight:paper-lines-4890
Nov 5, 2026
Merged

bherbruck merged 1 commit into
tangency-labs:drawingsfrom
CamWight:paper-lines-4890

Conversation

@CamWight

@CamWight CamWight commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Change

Text on a drawing sheet (a dimension's number, a title block's values) is set as filled glyph outlines in the drawing's font. Until now the only way to learn how wide a line of it would be was to set it and measure the result, and a long value couldn't be broken onto more lines to fit a box. This adds one call that measures a text for paper before it's set: its lines, each with its width, and the distance between them. Given a width, it breaks the text between words so each line holds as many words as fit. Setting the text then only places what was measured, so a width and the glyphs drawn can never disagree.

Part of #4890, into drawings. Nothing on a sheet changes yet: the title block's text uses it in a later PR.

Changes a default: no
No setting, command or saved data changes; existing text on paper is set as before.

What it does

In crates/sketch/src/paper_text.rs:

  • paper_lines(text, family, language, height, wrap, style) measures a text: its lines, each line's width in millimetres, and the line pitch. It breaks at each line break, and with wrap (a width in millimetres) also between words. Words are the text between spaces, put back one space apart on a wrapped line. A word is never cut, so a one-word line can be wider than wrap.
  • PaperLines::set(at, angle) places what was measured on the sheet: its runs and the fonts they use. It doesn't measure again.
  • paper_text is now paper_lines followed by set, so there is one rule for measuring and setting. Its results are unchanged.
  • A word the drawing's font lacks is measured in the font it falls back to (the fallback added in Drawing text F4: a character missing from the chosen font is drawn with another installed font (#4890) #10515), so a wrapped line with, say, a Chinese word is as wide as it's drawn.

Validation

Local, Windows, --profile ci, on drawings 69709bd: cargo check --all-targets of geom, sketch, doc, io and engine; fmt; clippy -D warnings; sketch paper_text tests: 47 passed. The same code was also checked as part of a group with the PRs that use it (dimension text, PNG text, title block text): geom paper 72, io paper 45, doc drawing 90, engine drawing 337, schema 191, and the engine's wasm build.

Tests (in paper_text_tests.rs):

  • Lines wrap between words to a width and never cut a word, and set gives the same runs as paper_text of the same lines.
  • A wrapped line with words the font lacks measures them in their fallback font (each line checked alone and set).
  • The marks dimensions use that the built-in font has (Ø ° ± ′ ″ × ≤ ≥) are its own glyphs.
  • Measuring refuses what setting would: a width that's NaN or infinite, a text over the size cap, a style the paper doesn't take, a NaN angle at set, a character no font has.
  • A fuzz test wraps random text (Latin, Hebrew with points, kana, Han, Hangul, tabs, breaks) to no width, -5, 0, 3, 12 and 40 mm: the words survive and the lines set, or the text is refused by name.

Planted faults, each caught by a failing test, then a clean run: wrap ignored; a line that fits exactly broken; the fallback lost when wrapping; a NaN width taken; the angle ignored at set.

Screenshots of the behavior

None: nothing on a sheet changes until a later PR uses it.

Integration status

One commit on drawings 69709bd (the latest when pushed).

@0xlillith's #12039 (a label's original text kept beside its runs, for the PDF writer's text) changes the same line loop in crates/sketch/src/paper_text.rs: it records each run's byte range in the original text as the lines are set. Whichever merges second carries the other across. With this PR the loop lives in PaperLines::set, so the ranges would be recorded there. One point for that join: a wrapped line is the text's words put back one space apart, so between two wrapped lines the original text has spaces, not a line break. #12039's check allows only line breaks between runs, so a wrapped value would need its ranges taken from the words, or the check would need to allow the spaces a wrap removed. Nothing wraps on a sheet until the title block text PR (#12357), and #12039's PDF reader comes later, so it can be settled when the two meet.

… to a width (tangency-labs#4890 B3b)

paper_lines measures a text for paper in the drawing's font and language:
its lines, each with its width, and the pitch between them, broken at each
line break and, given a width, between words (a word is never cut, so a
one-word line may be wider). A word the font lacks is measured in the font
it falls back to. PaperLines::set only places what was measured, and
paper_text is paper_lines then set, so one rule measures and sets text.

Ported from the personal PC's abefb37 onto today's fallback fonts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sketch sketcher and constraint solver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants